#include <vector>
#include <iostream>
#include "globals.h"
#include "MoteCollection.h"

/*!
 *A list of all possible conditions to trigger an event
*/
enum Condition {HIGHER, LOWER, EXACT};

/*!
 *A list of possible values for the parameter 'Value' in RegisterEvent
*/
enum Level {LIGHT = -1, DARK = -2};

using namespace std;

/*!
 * \brief EventManager registers events that are triggered if the condition is met
 * \author Khalid Alhokail, Vineet Gupta, Oren Melzer, David Schneider
 *
 */
class EventManager
{
	typedef struct Event
	{
		int id; //id of event
		int moteID; //id of mote that this event belongs to (-1 for all motes)
		int times; //#of time to execute this event (-1 infinity)
		Condition cond; //
		int value; //the desired reading
		int offset; //offset allowed from the desired reading
		void (*function)(void *, Mote *); //the function to execute
		void *arg; //the argument to pass
	}Event;

public:
	EventManager(MoteCollection **motelist);
	~EventManager();
	int RegisterEvent(int times, int moteID, Condition cond, int value, int offset, void (*function)(void *, Mote *), void *arg);
	bool DeleteEvent(int eventID);
	vector <Event> ActiveEvents;
	bool EvalEvent(Event *e, int *moteID);
	MoteCollection *motes;

private:
	int nextEventID;
};
